﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Messaging;

namespace ServiceController
{
    public delegate DataAccess.DataAccessResult SwapDelegate(String SubscriptionID, String CertificatePath, String ServiceName, String ProductionName, String SourceDeploymentName);
    
    public partial class ServiceController
    {

        SwapDelegate _SwapDelegate;
        public void SwapAsync(String SubscriptionID, String CertificatePath, String ServiceName, String ProductionName, String SourceDeploymentName, object UserState)
        {
            _SwapDelegate.BeginInvoke(SubscriptionID, CertificatePath, ServiceName, ProductionName, SourceDeploymentName,
                new AsyncCallback(SwapCallback), UserState);
        }

        private void SwapCallback(IAsyncResult ar)
        {
            AsyncResult aresult = (AsyncResult)ar;
            DataAccess.DataAccessResult result = _SwapDelegate.EndInvoke(ar);
            OnSwapComplete(new ServiceControllerEventArgs()
            {
                error = result.Error,
                UserState = ar.AsyncState,
                IsOperationSuccessful = result.IsOperationSuccessful,
            });
        }

        private DataAccess.DataAccessResult Swap(String SubscriptionID, String CertificatePath, String ServiceName, String ProductionName, String SourceDeploymentName)
        {
            DataAccess.DataAccessResult result = da.Swap(SubscriptionID, CertificatePath, ServiceName, ProductionName, SourceDeploymentName);
            return result;
        }
    }
}
